package com.tarena.lbs.basic.web.dao.repository;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tarena.lbs.basic.web.dao.mapper.StoreMapper;
import com.tarena.lbs.pojo.basic.entity.StoreSearchEntity;
import com.tarena.lbs.pojo.basic.po.StorePO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
@Slf4j
public class StoreRepository extends ServiceImpl<StoreMapper, StorePO> {
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private StoreESRepository storeESRepository;

    public void saveStore(StorePO poParam) {
        //只考虑新增到mysql持久层数据库
        storeMapper.insert(poParam);
        //写入到es 保存店铺id 名称 所属商家 和地理位置
        log.info("店铺仓储层 注入的 ES接口对象类:{}",storeESRepository.getClass().getName());
        //装配一个entity
        StoreSearchEntity entity=new StoreSearchEntity();
        //拷贝 id storeName businessId
        BeanUtils.copyProperties(poParam,entity);
        //手动补充地理定位数据 location latitude+","+longitude
        entity.setLocation(poParam.getStoreLatitude()+","+poParam.getStoreLongitude());
        storeESRepository.save(entity);
    }
}
